/*
Given a binary tree, find its depth (maximum height).
*/

/**
 * Definition for binary tree
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
 * };
 */
class Solution {
public:
    void _maxHeight(TreeNode *n, int level, int &h) {
        if (!n) return;
        if (level > h) {
            h = level;
        }
        /* in order traversal */
        _maxHeight(n->left, level+1, h);
        _maxHeight(n->right, level+1, h);
    }
    int maxHeight(TreeNode *root) {
        if (!root) return 0;
        int h = 1;
        _maxHeight(root->left, 2, h);
        _maxHeight(root->right, 2, h);
        return h;
    }
};
